package everest3;
import everest3.DateTextField;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;

public class Demo extends JFrame implements PropertyChangeListener
{
    private DateTextField startDateButton;
   
    private Date startDate;
    private Date endDate;

    private Demo() {
	super( "DateChooser demo" );
	addWindowListener
	    (
	     new WindowAdapter() {
		     public void windowClosing( WindowEvent e ) {
			 System.exit( 0 );
		     }
		 }
	     );

	startDate = new Date();
	endDate = new Date();

	startDateButton = new DateTextField();
	startDateButton.addPropertyChangeListener( "date", this );
	
	startDateButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jFormattedTextField1MouseClicked(evt);
            }
        });
	

	getContentPane().setLayout( new GridLayout(2,2) );
	getContentPane().add( new JLabel("Start date") );
	getContentPane().add( startDateButton );
	getContentPane().add( new JLabel("End date") );
	
	pack();
	setResizable( false );
    }

    public void propertyChange( PropertyChangeEvent e ) {
	DateTextField db = (DateTextField)e.getSource();
	
	if ( db != startDateButton )
	    System.out.print( "Start date changed: " );
	else
	    System.out.print( "End date changed: " );
	System.out.println( db.getDate() );
    }

    public static void main( String[] args ) {
    	try {
    		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    		
    	}
    	catch(Exception e)
    	{
    		
    	}
	(new Demo()).setVisible(true);
    }
    
        private void jFormattedTextField1MouseClicked(java.awt.event.MouseEvent evt) {                                                  
// TODO add your handling code here:
        if (evt.getButton()==evt.BUTTON3){
        	
        	Date newDate = startDateButton.DATE_CHOOSER.select(startDateButton.date);
			if ( newDate == null )
			    return;
			startDateButton.setDate( newDate );
        }
            
    } 
}

